
<?php
	require_once('class.phpmailer.php');
	include_once( "config.php");
   
   
    $email=$_POST['emailrecovery'];

	$query = "SELECT * 	          
			  FROM tbusers
              Where Email = '$email' ";
			
	mysql_query("set names utf8");
    
    $sql=mysql_query($query);
    $count=mysql_num_rows($sql);
    
    
    
    if ($count > 0){
        
        while ($row = mysql_fetch_array($sql))
            
         {$password = $row['Password'];	}


    $mail = new PHPMailer();
    $from = $sender;
    $from_name = $sendername;
    $subject = "Site D.A.R - Password Recovery";
    $body = "Password: ".$password ;
    $to = $email;

   // global $error;
	$mail = new PHPMailer();  // create a new object
	$mail->IsSMTP(); // enable SMTP
	$mail->SMTPDebug = 0;  // debugging: 1 = errors and messages, 2 = messages only
	$mail->SMTPAuth = true;  // authentication enabled
	$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
	$mail->Host = 'smtp.gmail.com';
	$mail->Port = 465; 
	$mail->Username = $Gmailusername;  
	$mail->Password = $Gmailpassword;           
	$mail->SetFrom($from, $from_name);
	$mail->Subject = $subject;
	$mail->Body = $body;
	$mail->AddAddress($to);
	if(!$mail->Send()) {
		//$error = 'Mail error: '.$mail->ErrorInfo; 
        $error = 'Mail error: Try again later'; 
		
	} else {
		$error = 'Message sent!';
		
	}

       
        
  
    }
    
    else{
        
        $error = 'Email not in our database';
        
        
    }
    
    
    
    echo $error;


	  
?>